<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">


    <title>StudentLogin</title>
    <link rel="stylesheet" href="css/StudentLogin.css" type="text/css">
    <link href="bootstrap-4.6.1-dist/css/bootstrap.min.css"
          rel="stylesheet" type="text/css">
</head>
<body>
<script src="jquery/jquery-3.6.0.min.js"></script>
<script src="bootstrap-4.6.1-dist/js/bootstrap.min.js"></script>

<div id="main">
    <div id="p"> <h1>Student Login</h1></div>
    <form id="loginForm">
        <div class="form-group row">
            <label class="col-form-label col-2 text-center"></label>
            <div class="col-8">
                <input type="text" name="loginName" class="form-control" id="loginName"
                       placeholder="账号\邮箱">
            </div>

        </div>
        <div class="form-group row">
            <label class="col-form-label col-2 text-center"></label>
            <div class="col-8">
                <input type="password" name="loginPwd" class="form-control"
                       placeholder="登录密码">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-form-label col-2"></label>
            <div class="col-8">
                <button type="button" id="btnLogin"
                        class="btn btn-lg btn-success">登录</button>
                <button type="button" id="btnSeg" class="btn btn-lg btn-success">
                    注册
                </button>
            </div>
        </div>
    </form>
</div>
</body>
<script>
    let infoName=sessionStorage.getItem("seg_form");
    console.log(infoName);
    let info = infoName.split('&');
    console.log(info[0]);
    jQuery("#loginName").val(info[0].substring(10,info[0].length));
</script>
<script>
    jQuery(function () {
        jQuery("#btnLogin").click(function(){
            let form=jQuery("#loginForm").serialize();
            jQuery.post("student/login",form,function (rst) {
                if(rst.length==0)
                {
                    alert("账号或密码有误!");
                }else{
                    console.log(rst[0]);
                    location.href="StudentDoCourse.html";
                    //把数据转为string类型，存放到浏览器中
                    sessionStorage.setItem("stu",JSON.stringify(rst[0]));
                }
            })
        });
    });
</script>
<script>
    jQuery(function () {
        jQuery("#btnSeg").click(function () {
            location.href="StudentReg.html";
        })
    })
</script>
</html>